package com.v1.video.activity;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.DisplayMetrics;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.iss.view.common.ToastAlone;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.umeng.analytics.MobclickAgent;
import com.v1.video.Constant;
import com.v1.video.R;
import com.v1.video.adapter.SearchKeyAdapter;
import com.v1.video.domain.Group;
import com.v1.video.domain.LoginInfo;
import com.v1.video.domain.PlayerInfo;
import com.v1.video.domain.ScenarioVideoInfo;
import com.v1.video.domain.SearchAlbumObj;
import com.v1.video.domain.SearchData2PageInfo;
import com.v1.video.domain.SearchData2PageObj;
import com.v1.video.domain.SearchGroupObj;
import com.v1.video.domain.SearchThemeObj;
import com.v1.video.domain.SearchUser2Obj;
import com.v1.video.domain.SearchVideo2Obj;
import com.v1.video.domain.SearchVideo2ObjInator;
import com.v1.video.domain.SearchVideo2PageInfo;
import com.v1.video.domain.SetHead;
import com.v1.video.domain.SpecialInfo;
import com.v1.video.domain.ThemeInfo;
import com.v1.video.domain.VideoDetailInfoNew;
import com.v1.video.option.db.SearchKeyDbUtil;
import com.v1.video.option.db.SearchKeyInfo;
import com.v1.video.option.util.SearchAboutUtil;
import com.v1.video.util.DensityUtil;
import com.v1.video.util.Helper;
import com.v1.video.util.Logger;
import com.v1.video.util.Utils;
import com.v1.video.view.waterfall.PLA_AbsListView;
import com.v1.video.view.waterfall.PLA_AbsListView.OnScrollListener;
import com.v1.video.view.waterfall.XListView;
import com.v1.video.view.waterfall.XListView.IXListViewListener;

import java.util.ArrayList;
import java.util.List;

/***
 * 二期的搜索页，3期继续用
 * @author fengtao
 * 
 */
public class OptionSearchActivity extends BaseActivity implements IXListViewListener,OnClickListener{
		
	private final String TAG = "OptionSearchActivity";
	/** 用户id */
    private String userId = "";
	/** 瀑布流的 */
    private XListView waterfull = null;
//    private XListView waterfullNoData = null;
    private int currentPage = 1; // 当前显示页数
    private int pageTotalVideo = 0;
    private VideoAdapter adapterVideo;
    
    private DisplayMetrics screenInfo;
    public static final int TYPE_REFRUSH = 1;
    public static final int TYPE_LOADMORE = 2;
    
    /** 关键词的布局 */
    private RelativeLayout layoutKeyWord = null;
    private RelativeLayout layoutNoKeyWord = null;
    private boolean isLayoutNoKey = false;
    private Button btnKeyWordClear = null;
    private ListView listView_search_key = null;
    private SearchKeyAdapter adapter = null;
    private boolean isLayoutKey = false;
    private EditText editSearchCon = null;
    private boolean isOnclickSearch = false;
    public String strKey = "";
    private ImageView btnClearText = null;
    
    //搜索的有结果 的相关内容
    private View headView = null;
    private RelativeLayout layoutPlayerBack = null;
    private TextView textPlayNum = null;
    private RelativeLayout layoutPlayerListBack = null;
    private LinearLayout layoutPlayerList = null;
    private ImageView ivSearchPlayerRight=null;
    
    private RelativeLayout layoutCircleBack = null;
    private TextView textCircleNum = null;
    private RelativeLayout layoutCircleListBack = null;
    private LinearLayout layoutCircleList = null;
    private ImageView ivSearchCircleRight=null;
    
    private RelativeLayout layoutSpecialBack = null;
    private TextView textSpecialNum = null;
    private RelativeLayout layoutSpecialListBack = null;
    private LinearLayout layoutSpecialList = null;
    private ImageView ivSearchSpecialRight=null;
    private int pageSize = 20;
    
    private RelativeLayout layoutThemeBack = null;
    private TextView textThemeNum = null;
    private RelativeLayout layoutThemeListBack = null;
    private LinearLayout layoutThemeList = null;
    private ImageView ivSearchThemeRight=null;
    
    
  //搜索的无结果
//    private View headViewNoData = null;
//    private boolean isVideoResultZero = false;
//    private RelativeLayout layoutSearchResultBack = null;    
    
    private RelativeLayout layoutHasData = null;
    private RelativeLayout layoutHasNoData = null;
    
    GetVideoDataAsync taskVideoData = null;
    private final int TYPE_HAS_DATA = 0;//搜索有数据;
    private final int TYPE_HAS_NoDATA = 1;//搜索无数据，即用推荐;
    private int type = TYPE_HAS_DATA;
    private int videos = 0;
    RelativeLayout aboutTitleBack;
    TextView aboutTitle;
    
    private View line_1 = null;
    private View line_2 = null;
    private View line_3 = null;
    private View line_4 = null;
    private View line_5 = null;
    private View line_6 = null;
    private View line_8 = null;
    private View line_7 = null;
    public static final int STATE_LOGIN = 0x0001;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_option_search);
	}

	@Override
	protected void initView() {
		// TODO Auto-generated method stub
		layoutKeyWord = (RelativeLayout) findViewById(R.id.search_keylist_back);
        layoutNoKeyWord = (RelativeLayout)findViewById(R.id.search_nocondition_back);
        btnKeyWordClear = (Button) findViewById(R.id.search_key_clear);
        listView_search_key = (ListView) findViewById(R.id.search_key_listview);

        editSearchCon = (EditText)findViewById(R.id.search_condition_edit);
        btnClearText = (ImageView)findViewById(R.id.search_btn_clear_key);
        
        waterfull = (XListView) findViewById(R.id.search_video_list);
//        waterfullNoData = (XListView) findViewById(R.id.search_video_list_nodata);
        
        headView = getLayoutInflater().inflate(
				R.layout.item_search_head_back, null);
        
        layoutPlayerBack = (RelativeLayout)headView.findViewById(R.id.item_search_player_back);
        textPlayNum = (TextView)headView.findViewById(R.id.item_search_player_num);
        layoutPlayerListBack = (RelativeLayout)headView.findViewById(R.id.item_search_playerlist_back);
        layoutPlayerList = (LinearLayout)headView.findViewById(R.id.item_search_player_list);
        ivSearchPlayerRight=(ImageView)headView.findViewById(R.id.item_search_player_right);
        
        layoutCircleBack = (RelativeLayout)headView.findViewById(R.id.item_search_circle_back);
        textCircleNum = (TextView)headView.findViewById(R.id.item_search_circle_num);
        layoutCircleListBack = (RelativeLayout)headView.findViewById(R.id.item_search_circlelist_back);
        layoutCircleList = (LinearLayout)headView.findViewById(R.id.item_search_circle_list);
        ivSearchCircleRight=(ImageView)headView.findViewById(R.id.item_search_circle_right);
        
        layoutSpecialBack = (RelativeLayout)headView.findViewById(R.id.item_search_special_back);
        textSpecialNum = (TextView)headView.findViewById(R.id.item_search_special_num);
        layoutSpecialListBack = (RelativeLayout)headView.findViewById(R.id.item_search_speciallist_back);
        layoutSpecialList = (LinearLayout)headView.findViewById(R.id.item_search_special_list);
        ivSearchSpecialRight=(ImageView)headView.findViewById(R.id.item_search_special_right);
        
        layoutThemeBack = (RelativeLayout)headView.findViewById(R.id.item_search_theme_back);
        textThemeNum = (TextView)headView.findViewById(R.id.item_search_theme_num);
        layoutThemeListBack = (RelativeLayout)headView.findViewById(R.id.item_search_themelist_back);
        layoutThemeList = (LinearLayout)headView.findViewById(R.id.item_search_theme_list);
        ivSearchThemeRight=(ImageView)headView.findViewById(R.id.item_search_theme_right);
        
        
        aboutTitle = (TextView) headView.findViewById(R.id.video_about_title);
        aboutTitleBack = (RelativeLayout) headView.findViewById(R.id.video_about_title_back);        
        
        line_1 = (View) headView.findViewById(R.id.item_search_line_1);
        line_2 = (View) headView.findViewById(R.id.item_search_line_2);
        line_3 = (View) headView.findViewById(R.id.item_search_line_3);
        line_4 = (View) headView.findViewById(R.id.item_search_line_4);
        line_5 = (View) headView.findViewById(R.id.item_search_line_5);
        line_6 = (View) headView.findViewById(R.id.item_search_line_6);
        line_7 = (View) headView.findViewById(R.id.item_search_line_7);
        line_8 = (View) headView.findViewById(R.id.item_search_line_8);
        
        layoutHasData = (RelativeLayout)headView.findViewById(R.id.item_search_hasdata_back);
        layoutHasNoData = (RelativeLayout)headView.findViewById(R.id.item_search_hasnodata_back);
        
//        headViewNoData = getLayoutInflater().inflate(
//				R.layout.item_search_noresult, null);
//        layoutSearchResultBack = (RelativeLayout)headViewNoData.findViewById(R.id.item_search_result_back);
        waterfull.addHeaderView(headView);
//        waterfullNoData.addHeaderView(headViewNoData);
        waterfull.setVisibility(View.GONE);
//        waterfullNoData.setVisibility(View.GONE);
	}
	
	@Override
	protected void initData() {
		// TODO Auto-generated method stub
		if (LoginInfo.getInstance().isLogin()) {
            userId = LoginInfo.getInstance().getUserId();
        }
		
//		((TextView)findViewById(R.id.tv_l)).setText(R.string.cancel);
        ((TextView)findViewById(R.id.tv_title)).setText(R.string.search_label_hint);
        screenInfo = Utils.getScreenInfo(this);
        initKeyWord();
        
        adapterVideo = new VideoAdapter(new ArrayList<VideoDetailInfoNew>());
        waterfull.setAdapter(adapterVideo);
        waterfull.setPullLoadEnable(false);
        waterfull.setPullRefreshEnable(false);
        waterfull.setXListViewListener(this);
//        waterfullNoData.setAdapter(adapterVideo);
//        waterfullNoData.setPullLoadEnable(false);
//        waterfullNoData.setPullRefreshEnable(false);
//        waterfullNoData.setXListViewListener(this);
//        findViewById(R.id.tv_result).setOnClickListener(new OnClickListener(){
//
//			@Override
//			public void onClick(View v) {
//				finish();
//			}});
        findViewById(R.id.lay_result).setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                finish();
            }
        });
        editSearchCon.addTextChangedListener(watcher);
//        getPlayerListCeShi();
	}
	
//	private void getPlayerListCeShi(){
//		layoutKeyWord.setVisibility(View.GONE);
//		layoutNoKeyWord.setVisibility(View.GONE);
//		headView.setVisibility(View.VISIBLE);
//		ArrayList<PlayerInfo> listPlayer = new ArrayList<PlayerInfo>();
//		for(int i = 0; i <= 20;i++){
//        	PlayerInfo player = new PlayerInfo();
//        	player.setUserName("赵薇导演");
//        	player.setUserImg("http://tp2.sinaimg.cn/1832755317/50/22884068310/1");
//        	listPlayer.add(player);
//        }
//		getPlayerView(listPlayer);
//		
//		ArrayList<Group> listCircle = new ArrayList<Group>();
//		for(int i = 0; i <= 20;i++){
//        	Group info = new Group();
//        	if(i == 0){
//        		info.setGname("赵薇");
//        	}else if(i == 1){
//        		info.setGname("赵薇陈坤");
//        	}else if(i == 2){
//        		info.setGname("赵薇佟大焦");
//        	}else {
//        		info.setGname("赵薇XXXXXXX");
//        	}
//        	listCircle.add(info);
//        }
//		getCircleView(listCircle);
//		
//		ArrayList<SpeciaUserlInfo> listSpecial = new ArrayList<SpeciaUserlInfo>();
//		for(int i = 0; i <= 20;i++){
//        	SpeciaUserlInfo info = new SpeciaUserlInfo();
//        	if(i == 0){
//        		info.setAname("赵薇");
//        	}else if(i == 1){
//        		info.setAname("赵薇陈坤");
//        	}else if(i == 2){
//        		info.setAname("赵薇佟大焦");
//        	}else {
//        		info.setAname("赵薇XXXXXXX");
//        	}
//        	listSpecial.add(info);
//        }
//		getSpecialView(listSpecial);
//	}
	
	private void initKeyWord() {
        ArrayList<SearchKeyInfo> listKey = SearchKeyDbUtil.getKeyInfo(OptionSearchActivity.this);
        if (listKey == null) {
            // adapter = new SearchKeyAdapter(OptionSearchActivity.this);
            // listView_search_key.setAdapter(adapter);
            layoutNoKeyWord.setVisibility(View.VISIBLE);
            isLayoutNoKey = true;
        }else if(listKey.size() <= 0){
            layoutNoKeyWord.setVisibility(View.VISIBLE);
            isLayoutNoKey = true;
        } else if (listKey.size() > 0) {
            adapter = new SearchKeyAdapter(OptionSearchActivity.this, listKey);
            LayoutParams layoutParams = listView_search_key.getLayoutParams();
            layoutParams.height = DensityUtil.dip2px(OptionSearchActivity.this, 50*listKey.size());
            layoutParams.width = LayoutParams.MATCH_PARENT;
            listView_search_key.setLayoutParams(layoutParams);
            listView_search_key.setAdapter(adapter);
            layoutKeyWord.setVisibility(View.VISIBLE);
            isLayoutKey = true;            
        }
    }
	private void hideSoftInput() {
        ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
                OptionSearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }
	private void editOnClick() {
        editSearchCon.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View arg0, MotionEvent arg1) {
                // TODO Auto-generated method stub

                List<SearchKeyInfo> listKey = SearchKeyDbUtil
                        .getKeyInfo(OptionSearchActivity.this);
                waterfull.setVisibility(View.GONE);
//                waterfullNoData.setVisibility(View.GONE);
                
                if (listKey == null) {
                    layoutNoKeyWord.setVisibility(View.VISIBLE);
                    isLayoutNoKey = true;
                } else if (listKey.size() <= 0) {
                    layoutNoKeyWord.setVisibility(View.VISIBLE);
                    isLayoutNoKey = true;
                } else if (listKey.size() > 0) {
                    layoutNoKeyWord.setVisibility(View.GONE);
                    isLayoutNoKey = false;
                    layoutKeyWord.setVisibility(View.VISIBLE);
                    isLayoutKey = true;
                    if (adapter == null) {
                        adapter = new SearchKeyAdapter(OptionSearchActivity.this, listKey);
                        LayoutParams layoutParams = listView_search_key.getLayoutParams();
                        layoutParams.height = DensityUtil.dip2px(OptionSearchActivity.this, 50*listKey.size());
                        layoutParams.width = LayoutParams.MATCH_PARENT;
                        listView_search_key.setLayoutParams(layoutParams);
                        listView_search_key.setAdapter(adapter);
                    } else {
                    	LayoutParams layoutParams = listView_search_key.getLayoutParams();
                        layoutParams.height = DensityUtil.dip2px(OptionSearchActivity.this, 50*listKey.size());
                        layoutParams.width = LayoutParams.MATCH_PARENT;
                        listView_search_key.setLayoutParams(layoutParams);
                        adapter.updata(listKey);
                    }
                }
                return false;
            }
        });
        editSearchCon.setOnKeyListener(new OnKeyListener() {

            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                // TODO Auto-generated method stub
                 if (keyCode == KeyEvent.KEYCODE_ENTER) {
                     if (isOnclickSearch) {
                         Logger.i(TAG, "editSearchCon_onClick");
                         return false;
                     }
                     if (!isOnclickSearch) {
                         isOnclickSearch = true;
                     }
                     layoutNoKeyWord.setVisibility(View.GONE);
                     isLayoutNoKey = false;
                     Logger.i(TAG, "editSearchCon_onClick11111111");
                     String strKey = editSearchCon.getText().toString().trim();
                     if (strKey.equals("")) {
                         hideSoftInput();
                         editSearchCon.setText("");
                         layoutKeyWord.setVisibility(View.INVISIBLE);
                         isLayoutKey = false;
                         isOnclickSearch = false;
                         waterfull.setPullLoadEnable(false);
                       //请输入搜索关键词
                         ToastAlone.showToast(OptionSearchActivity.this, getResources().getString(R.string.search_no), 1);
                         return false;
                     }
                     if(!Helper.checkConnection(OptionSearchActivity.this)){
                         ToastAlone.showToast(OptionSearchActivity.this, getResources().getString(R.string.net_no), 1);
                         hideSoftInput();
                         layoutKeyWord.setVisibility(View.INVISIBLE);
                         isLayoutKey = false;
//                         isVideoResultZero = false;
//                         layoutSearchResultBack.setVisibility(View.GONE);   
                         
                         return false;
                     }
                     OptionSearchActivity.this.strKey = strKey;
                     hideSoftInput();
                     layoutKeyWord.setVisibility(View.INVISIBLE);
                     isLayoutKey = false;
//                     isVideoResultZero = false;
//                     layoutSearchResultBack.setVisibility(View.GONE);
                     searchToGetData(strKey);

                     List<SearchKeyInfo> listKey = SearchKeyDbUtil
                             .getKeyInfo(OptionSearchActivity.this);
                     if (listKey == null) {
                         SearchKeyInfo keyInfo = new SearchKeyInfo();
                         keyInfo.key = strKey;
                         SearchKeyDbUtil.addSearchKeyInfo(OptionSearchActivity.this, keyInfo);
                     } else if (listKey.size() <= 0) {
                         SearchKeyInfo keyInfo = new SearchKeyInfo();
                         keyInfo.key = strKey;
                         SearchKeyDbUtil.addSearchKeyInfo(OptionSearchActivity.this, keyInfo);
                     } else {
                         boolean isSame = false;
                         for (int i = 0; i < listKey.size(); i++) {
                             SearchKeyInfo keyInfo = listKey.get(i);
                             if (strKey.equals(keyInfo.key)) {
                                 isSame = true;
                                 break;
                             }
                         }
                         if (!isSame) {
                             SearchKeyInfo keyInfo = new SearchKeyInfo();
                             keyInfo.key = strKey;
                             if (listKey.size() >= 10) {
                                 SearchKeyDbUtil.deleteSearchKey(OptionSearchActivity.this,
                                         listKey.get(0).key);
                             }
                             SearchKeyDbUtil.addSearchKeyInfo(OptionSearchActivity.this, keyInfo);
                         }
                     }
                 }
                return false;
            }
        });
    }
	
	private void layoutKeyWordOnClick() {
        listView_search_key.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> view, View arg1, int pos, long arg3) {
                layoutNoKeyWord.setVisibility(View.GONE);
                isLayoutNoKey = false;
                isLayoutKey = false;
                layoutKeyWord.setVisibility(View.INVISIBLE);
                hideSoftInput();
//                isVideoResultZero = false;
                String strKey = ((SearchKeyInfo) adapter.getItem(pos)).key;
                editSearchCon.setText(strKey);                
                OptionSearchActivity.this.strKey = strKey;
                Logger.i(TAG, "点击关键词=" + strKey);
                if(!Helper.checkConnection(OptionSearchActivity.this)){
                    ToastAlone.showToast(OptionSearchActivity.this, getResources().getString(R.string.net_no), 1);                    
//                    curPagePaike = 0;
                }else{
//                    curPagePaike = 0;
                    searchToGetData(strKey);
                }
            }
            
        });
        btnKeyWordClear.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                layoutKeyWord.setVisibility(View.INVISIBLE);
                isLayoutKey = false;
                List<SearchKeyInfo> listKey = SearchKeyDbUtil
                        .getKeyInfo(OptionSearchActivity.this);
                for (int i = 0; i < listKey.size(); i++) {
                    SearchKeyInfo keyInfo = listKey.get(i);
                    SearchKeyDbUtil.deleteSearchKey(OptionSearchActivity.this, keyInfo);
                }
                layoutNoKeyWord.setVisibility(View.VISIBLE);
                isLayoutNoKey = true;
            }
        });
    }
	
	private void searchToGetData(String strKey) {
	        layoutKeyWord.setVisibility(View.GONE);
	        isLayoutKey = false;
	        currentPage = 1;
	        type = TYPE_HAS_DATA;
	        waterfull.setVisibility(View.GONE);
//			waterfullNoData.setVisibility(View.GONE);
			if(adapterVideo != null){
				adapterVideo = null;
				adapterVideo = new VideoAdapter(new ArrayList<VideoDetailInfoNew>());
				waterfull.setAdapter(adapterVideo);
//				waterfullNoData.setAdapter(adapterVideo);
			}
	        new GetDataAsync(""+currentPage,strKey,userId,TYPE_REFRUSH).execute();
	//        mAdapterView.setPullRefreshEnable(true);
	//        focusPullToRefreshListView.setMode(Mode.PULL_FROM_END);
	//        taskVideo = new GetVideoDataTask(currentPage + "", strKey, userId,TYPE_REFRUSH);
	//        taskVideo.execute();
    }

	@Override
	protected void setListener() {
		// TODO Auto-generated method stub
		ivSearchPlayerRight.setOnClickListener(this);
		ivSearchCircleRight.setOnClickListener(this);
		ivSearchSpecialRight.setOnClickListener(this);
		ivSearchThemeRight.setOnClickListener(this);
		editOnClick();
		layoutKeyWordOnClick();
		btnClearText.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				editSearchCon.setText("");
			}
		});
		
		waterfull.setOnScrollListener(new OnScrollListener() {

			@Override
			public void onScrollStateChanged(PLA_AbsListView view,
					int scrollState) {
				switch (scrollState) {
				case OnScrollListener.SCROLL_STATE_IDLE:
					ImageLoader.getInstance().resume();
					break;
				case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
					ImageLoader.getInstance().pause();
					break;
				case OnScrollListener.SCROLL_STATE_FLING:
					ImageLoader.getInstance().pause();
					break;
				}
				waterfull.onScrollStateChanged(view,scrollState);
			}

			@Override
			public void onScroll(PLA_AbsListView view, int firstVisibleItem,
					int visibleItemCount, int totalItemCount) {
				waterfull.onScroll(view,firstVisibleItem,visibleItemCount,totalItemCount);
				
			}});
	}

	@Override
    public void onBackPressed() {
        // TODO Auto-generated method stub
        super.onBackPressed();
    }
	
	private void getPlayerView(ArrayList<PlayerInfo> listPlayer){
		int size = 0;
		if(listPlayer.size() >= 4){
			size = 4;
		}else{
			size = listPlayer.size();
		}
		if(layoutPlayerList != null){
			layoutPlayerList.removeAllViews();
		}
		for(int i= 0; i < size ;i++){
			Logger.i(TAG, "getPlayerView执行了。。。");
			View view = View.inflate(OptionSearchActivity.this,
					R.layout.item_search_player_list, null);
			ImageView head = (ImageView) view
					.findViewById(R.id.item_search_player_head);
			ImageView head_v = (ImageView) view
					.findViewById(R.id.userHeadImg_v);
			TextView name = (TextView) view
					.findViewById(R.id.item_search_player_name);
			final PlayerInfo info = listPlayer.get(i);
			if(info.getNickName() == null || info.getNickName().equals("") || info.getNickName().equals("null")){
				name.setText(info.getUserName());
			}else{
				name.setText(info.getNickName());
			}
			if(info.getIsCertification() == 0){
				head_v.setVisibility(View.GONE);
			}else{
				head_v.setVisibility(View.VISIBLE);
			}
			SetHead setHead = new SetHead();
			setHead.setHead(info.getUserImg(), info.getSex(), head);
			head.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Logger.i(TAG, "进个人中心");
					String clickUserId;
					if(LoginInfo.getInstance().isLogin()){
	                       if( LoginInfo.getInstance().getUserId().equals(""+info.getUserId()/*userID*/)){
//	                           startActivity(new Intent(v.getContext(),PersonalHomeActivity.class));
	                       }else{
	                           //clickUserId = info.getFocusUserId();
	                    	   clickUserId=""+info.getUserId();
	                           startActivity(new Intent(v.getContext(), OtherPersonHomeActivity.class).putExtra("userId", clickUserId));
	                       }
	                   }else{
	                       clickUserId = ""+info.getUserId();
	                       startActivity(new Intent(v.getContext(), OtherPersonHomeActivity.class).putExtra("userId", clickUserId));
	                   }
				}
			});
			// Logger.i(TAG, "galleryCircleTuijian.addView(view)");
			layoutPlayerList.addView(view);
		}
	}
	
	private void getCircleView(ArrayList<Group> listCircle){
		int size = 0;
		if(listCircle.size() >= 3){
			size = 3;
		}else{
			size = listCircle.size();
		}
		if(layoutCircleList != null){
			layoutCircleList.removeAllViews();
		}
		for(int i= 0; i < size ;i++){
			Logger.i(TAG, "getCircleView执行了。。。");
			final Group info = listCircle.get(i);
			View view = View.inflate(OptionSearchActivity.this,
					R.layout.item_search_cicle_list, null);
			view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.FILL_PARENT));
			TextView name = (TextView) view
					.findViewById(R.id.item_search_cicle_name);			
			name.setText(info.getGname());
			
			name.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Logger.i(TAG, "进圈子详情页");
//					Intent intent=new Intent(OptionSearchActivity.this,MyCreatedQuanziActivity.class);
//					/*intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
//							| Intent.FLAG_ACTIVITY_SINGLE_TOP);*/
//					intent.putExtra("userid", "1");
//					intent.putExtra("groupID", info.getId());
//					OptionSearchActivity.this.startActivity(intent);
				}
			});
			// Logger.i(TAG, "galleryCircleTuijian.addView(view)");
			layoutCircleList.addView(view);
		}
	}
	
	private void getSpecialView(ArrayList<SpecialInfo> listSpecial){
		int size = 0;
		if(listSpecial.size() >= 3){
			size = 3;
		}else{
			size = listSpecial.size();
		}
		if(layoutSpecialList != null){
			layoutSpecialList.removeAllViews();
		}
		for(int i= 0; i < size ;i++){
			Logger.i(TAG, "getSpecialView执行了。。。");
			final SpecialInfo info = listSpecial.get(i);
			View view = View.inflate(OptionSearchActivity.this,
					R.layout.item_search_cicle_list, null);
			view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.FILL_PARENT,1));
			TextView name = (TextView) view
					.findViewById(R.id.item_search_cicle_name);		
			if(info.getAname() != null && !info.getAname().equals("")){
				name.setText(info.getAname());
			}else{
				name.setText(info.getOaName());
			}
			
			name.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Logger.i(TAG, "进专辑详情页");
					//2014-12-26 页面跳转丢失必要参数
//					Intent intent=new Intent(OptionSearchActivity.this,MyZhuanjiDetailActivity.class);
//					intent.putExtra("userId", info.getUserId()+"");
//					intent.putExtra("albumId", info.getId()+"");
//					intent.putExtra("aname", info.getAname());
//					OptionSearchActivity.this.startActivity(intent);
				}
			});
			// Logger.i(TAG, "galleryCircleTuijian.addView(view)");
			layoutSpecialList.addView(view);
		}
		
	}
	
	private void getThemeView(ArrayList<ThemeInfo> listTheme){
		int size = 0;
		if(listTheme.size() >= 3){
			size = 3;
		}else{
			size = listTheme.size();
		}
		if(layoutThemeList != null){
			layoutThemeList.removeAllViews();
		}
		for(int i= 0; i < size ;i++){
			Logger.i(TAG, "getSpecialView执行了。。。");
			final ThemeInfo info = listTheme.get(i);
			View view = View.inflate(OptionSearchActivity.this,
					R.layout.item_search_cicle_list, null);
			view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.FILL_PARENT,1));
			TextView name = (TextView) view
					.findViewById(R.id.item_search_cicle_name);		
//			if(info.getAname() != null && !info.getAname().equals("")){
//				name.setText(info.getAname());
//			}else{
//				name.setText(info.getOaName());
//			}
			name.setText(info.getTopicName());
			name.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Logger.i(TAG, "进话题详情页");
					//2014-12-26 页面跳转丢失必要参数
				}
			});
			// Logger.i(TAG, "galleryCircleTuijian.addView(view)");
			layoutThemeList.addView(view);
		}
		
	}
	
	/**
     * 添加内容
     * 
     * @param pageindex
     * @param type 1为下拉刷新 2为加载更多
     */
    private void AddItemToContainer(int pageindex, int type) {

        if (taskVideoData == null || taskVideoData.getStatus() != AsyncTask.Status.RUNNING) {
//            if(pageindex >= pageTotalVideo){
//                pageindex = currentPage = 0;
//            }
        	taskVideoData = new GetVideoDataAsync(""+pageindex,strKey,userId,type);
        	taskVideoData.execute();
        }
    }
	
	/**
     * 搜索数据
     */
    private class GetDataAsync extends AsyncTask<Void, Void, Boolean> {
        
        private String errorMsg = "";
        
        private ProgressDialog pd;
        String pageIndex = "";

        String strKey = "";

        String userId;

        SearchData2PageInfo searchPageInfo = null;
        int state = 0;
        ArrayList<PlayerInfo> listPlayer = new ArrayList<PlayerInfo>();
        ArrayList<Group> listCircle = new ArrayList<Group>();
        ArrayList<SpecialInfo> listSpecial = new ArrayList<SpecialInfo>();
        ArrayList<ThemeInfo> listTheme = new ArrayList<ThemeInfo>();
        public GetDataAsync(String pageIndex, String strKey, String userId, int type) {
            this.pageIndex = pageIndex;
            this.strKey = strKey;
            this.userId = userId;
            this.state = type;
        }
        
        //http://tp2.sinaimg.cn/1832755317/50/22884068310/1
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pd = Utils.getProgressDialog(OptionSearchActivity.this,getResources().getString(R.string.get_data), this);
            pd.show();
        }
        
        @Override
        protected Boolean doInBackground(Void... params) {
            try {
            	SearchAboutUtil util = new SearchAboutUtil();
            	searchPageInfo = util.getDataBySearch(strKey, ""+pageSize, ""+pageIndex);

            } catch (Exception e) {
                e.printStackTrace();
                errorMsg = e.getMessage();
            }
            return false;
        }
        @Override
		protected void onCancelled() {
			if(waterfull != null){
				waterfull.stopLoadMore();
				waterfull.stopRefresh();
			}
			super.onCancelled();
		}

        @Override
        protected void onPostExecute(Boolean result) {
            super.onPostExecute(result);
            if(pd != null && pd.isShowing()){
                pd.cancel();
            }
            if (state == 1) {
                waterfull.stopRefresh();
//                waterfullNoData.stopRefresh();
            } else if (state == 2) {
            	waterfull.stopLoadMore();
//            	waterfullNoData.stopLoadMore();
            }          
            isOnclickSearch = false;
            if (errorMsg.equals("")) {
            	waterfull.setPullLoadEnable(true);
//            	waterfullNoData.setPullLoadEnable(true);
            	if(searchPageInfo != null){
            		SearchData2PageObj obj = searchPageInfo.getObj();
            		if(searchPageInfo.getMsg() != null && searchPageInfo.getMsg().equals("suggest")){//搜索不到数据，故为推荐视频
            			type = TYPE_HAS_NoDATA;
            			waterfull.setVisibility(View.VISIBLE);
//            			waterfull.setVisibility(View.GONE);
//            			waterfullNoData.setVisibility(View.VISIBLE);
            			layoutHasData.setVisibility(View.GONE);
            			layoutHasNoData.setVisibility(View.VISIBLE);
            			if(obj != null && obj.getList() != null){
            	            if (state == 1) {
            	                adapterVideo.LoadRefrush(obj.getList());
            	            } else if (state == 2) {
            	                adapterVideo.LoadMore(obj.getList());
            	            }
            	            if(obj.getList().size() < pageSize){
//            	                waterfullNoData.setPullLoadEnable(false);
            	                waterfull.setPullLoadEnable(false);
            	            }
            	            adapterVideo.notifyDataSetChanged();
            			}else {
//        	                waterfullNoData.setPullRefreshEnable(false);
        	                waterfull.setPullRefreshEnable(false);
        	                ToastAlone.showToast(OptionSearchActivity.this, "数据为空", 1);
        	            }
            		}else{
            			type = TYPE_HAS_DATA;
            			waterfull.setVisibility(View.VISIBLE);
//            			waterfullNoData.setVisibility(View.GONE);
            			layoutHasData.setVisibility(View.VISIBLE);
            			layoutHasNoData.setVisibility(View.GONE);
            			if(obj != null){
            				SearchVideo2Obj videoData =  obj.getPageListVideoDetail();
            				SearchGroupObj groupData = obj.getPageListGroup();
            				SearchAlbumObj albumData = obj.getPageListAlbum();
            				SearchUser2Obj userData = obj.getPageListUserInfo();
            				SearchThemeObj themeData = obj.getPageListTag();
            				layoutSpecialBack.setVisibility(View.GONE);
            				layoutSpecialListBack.setVisibility(View.GONE);
                         	layoutPlayerBack.setVisibility(View.GONE);
                         	layoutPlayerListBack.setVisibility(View.GONE);
                         	layoutCircleBack.setVisibility(View.GONE);
                         	layoutCircleListBack.setVisibility(View.GONE);
                         	layoutThemeBack.setVisibility(View.GONE);
                         	layoutThemeListBack.setVisibility(View.GONE);
                         	line_1.setVisibility(View.GONE);
                         	line_2.setVisibility(View.GONE);
                         	line_3.setVisibility(View.GONE);
                         	line_4.setVisibility(View.GONE);
                         	line_5.setVisibility(View.GONE);
                         	line_6.setVisibility(View.GONE);
                         	line_7.setVisibility(View.GONE);
                         	line_8.setVisibility(View.GONE);
                         	if(themeData != null && themeData.getList() != null && themeData.getList().size() > 0)
                         	{
//                         		for(int i = 0; i < 20;i++){
//	                         		ThemeInfo themeInfo = new ThemeInfo();
//	                         		themeInfo.setAname("大话西游西游降魔篇"+i);
//	                         		listTheme.add(themeInfo);
//	                         	}
                         		listTheme.clear();
                         		listTheme.addAll(themeData.getList());
	                         	layoutThemeBack.setVisibility(View.VISIBLE);
	                         	layoutThemeListBack.setVisibility(View.VISIBLE);
	                         	String str = OptionSearchActivity.this.getResources().getString(R.string.search_title_about_theme);
	                         	//textThemeNum.setText(str+"("+listTheme.size()+")");
	                         	textThemeNum.setText(str+"("+themeData.getPaginator().getItems()+")");
	                         	getThemeView(listTheme);
	                       		ivSearchThemeRight.setVisibility(View.VISIBLE);
	                       		line_4.setVisibility(View.VISIBLE);
                         	}
            				if(groupData != null && groupData.getList() != null && groupData.getList().size() > 0){
            					listCircle.clear();
            					listCircle.addAll(groupData.getList());
            					layoutCircleBack.setVisibility(View.VISIBLE);
                             	layoutCircleListBack.setVisibility(View.VISIBLE);
                             	
                             	 String str = OptionSearchActivity.this.getResources().getString(R.string.search_title_about_circle);
                            	 //textCircleNum.setText(str+"("+listCircle.size()+")");
                             	textCircleNum.setText(str+"("+groupData.getPaginator().getItems()+")");
                            	getCircleView(listCircle);
//                            	if(listCircle.size() <= 3){
//                            		ivSearchCircleRight.setVisibility(View.GONE);
//                            	}else{
                            		ivSearchCircleRight.setVisibility(View.VISIBLE);
                            		line_2.setVisibility(View.VISIBLE);
                            		line_3.setVisibility(View.VISIBLE);
//                            	}
            				}else{
            					listCircle.clear();
            					layoutCircleBack.setVisibility(View.GONE);
                             	layoutCircleListBack.setVisibility(View.GONE);
            				}
            				if(albumData != null && albumData.getList() != null && albumData.getList().size() > 0){
            					layoutSpecialBack.setVisibility(View.VISIBLE);
                             	layoutSpecialListBack.setVisibility(View.VISIBLE);
                             	listSpecial.addAll(albumData.getList());
                             	String str = OptionSearchActivity.this.getResources().getString(R.string.search_title_about_label);
                             	//textSpecialNum.setText(str+"("+listSpecial.size()+")");
                             	textSpecialNum.setText(str+"("+albumData.getPaginator().getItems()+")");
                             	getSpecialView(listSpecial);
                             	if(listSpecial.size() <= 3){
                            		ivSearchSpecialRight.setVisibility(View.GONE);
                            	}else{
                            		ivSearchSpecialRight.setVisibility(View.VISIBLE);
                            	}
                             	line_5.setVisibility(View.VISIBLE);
                        		line_8.setVisibility(View.VISIBLE);                             	
            				}else{
            					layoutSpecialBack.setVisibility(View.GONE);
                             	layoutSpecialListBack.setVisibility(View.GONE);
            				}
            				if(userData != null && userData.getList() != null && userData.getList().size() > 0){
            					layoutPlayerBack.setVisibility(View.VISIBLE);
            					layoutPlayerListBack.setVisibility(View.VISIBLE);
            					listPlayer.addAll(userData.getList());
            					String str = OptionSearchActivity.this.getResources().getString(R.string.search_title_about_player);
                            	//textPlayNum.setText(str+"("+listPlayer.size()+")");
            					textPlayNum.setText(str+"("+userData.getPaginator().getItems()+")");
                             	getPlayerView(listPlayer);
                             	if(listPlayer.size() <= 4){
                            		ivSearchPlayerRight.setVisibility(View.GONE);
                            	}else{
                            		ivSearchPlayerRight.setVisibility(View.VISIBLE);
                            	}
                             	line_1.setVisibility(View.VISIBLE);
            				}else{
            					layoutPlayerListBack.setVisibility(View.GONE);
            					layoutPlayerBack.setVisibility(View.GONE);
            				}
            				
            				if(videoData != null && videoData.getList() != null){
            					SearchVideo2ObjInator pageInfo = videoData.getPaginator();
                				if(pageInfo != null){
                					videos = pageInfo.getItems();
                					aboutTitle.setText("相关视频("+videos+")");
                				}
                				aboutTitleBack.setVisibility(View.VISIBLE);
                				if(videoData.getList().size() <= 0){
                					aboutTitleBack.setVisibility(View.GONE);
                				}
                				line_6.setVisibility(View.VISIBLE);
            	                if (state == 1) {
            	                    adapterVideo.LoadRefrush(videoData.getList());
            	                } else if (state == 2) {
            	                    adapterVideo.LoadMore(videoData.getList());
            	                }
            	                if(videoData.getList().size() < pageSize){
//            	                    waterfullNoData.setPullLoadEnable(false);
            	                    waterfull.setPullLoadEnable(false);
            	                }
//            	                adapterVideo.notifyDataSetChanged();
            				}else {
            					aboutTitleBack.setVisibility(View.GONE);
            					aboutTitle.setVisibility(View.GONE);
//        	                    waterfullNoData.setPullRefreshEnable(false);
    	                    	waterfull.setPullRefreshEnable(false);
        	                    ToastAlone.showToast(OptionSearchActivity.this, "数据为空", 1);
        	                }
            			}else{
            				ToastAlone.showToast(OptionSearchActivity.this, "未知错误", 1);
            			}
            		}
            		
            	}else{
            		ToastAlone.showToast(OptionSearchActivity.this, "未知错误", 1);
            	}
//            	 if(listPlayer.size() <= 0){
//                 	layoutPlayerBack.setVisibility(View.GONE);
//                 	layoutPlayerListBack.setVisibility(View.GONE);
//                 }else{
//                	 String str = OptionSearchActivity.this.getResources().getString(R.string.search_title_about_player);
//                	textPlayNum.setText(str+"("+listPlayer.size()+")");
//                 	getPlayerView(listPlayer);
//                 }
            	 
                      
            } else {
                ToastAlone.showToast(OptionSearchActivity.this, errorMsg, 1);
            }
        }
    }
    
    private class GetVideoDataAsync extends AsyncTask<Void, Void, Boolean> {
        
        private String errorMsg = "";
        private ProgressDialog pd;
        SearchVideo2PageInfo videoPageInfo;
        String pageIndex = "";

        String strKey = "";

        String userId;
        private List<VideoDetailInfoNew> videolist;
        int state = 0;
        public GetVideoDataAsync(String pageIndex, String strKey, String userId, int type) {
            this.pageIndex = pageIndex;
            this.strKey = strKey;
            this.userId = userId;
            this.state = type;
        }
        
        public GetVideoDataAsync(String pageIndex, String strKey) {
            this.pageIndex = pageIndex;
            this.strKey = strKey;
        }
        
        //http://tp2.sinaimg.cn/1832755317/50/22884068310/1
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pd = Utils.getProgressDialog(OptionSearchActivity.this,getResources().getString(R.string.get_data), this);
            pd.show();
        }
        
        @Override
        protected Boolean doInBackground(Void... params) {
            try {
            	SearchAboutUtil util = new SearchAboutUtil();
                if(type == TYPE_HAS_DATA){
                	videoPageInfo = util.getVideoBySearch(strKey, ""+pageSize, pageIndex);
                }else{
                	videoPageInfo = util.getVideoBySearchRecommend(strKey, ""+pageSize, pageIndex);
                }
                
            } catch (Exception e) {
                e.printStackTrace();
                errorMsg = e.getMessage();
            }
            return false;
        }
        
        @Override
        protected void onPostExecute(Boolean result) {
            super.onPostExecute(result);
            if(pd != null && pd.isShowing()){
                pd.cancel();
            }            
            if (state == 1) {
                waterfull.stopRefresh();

            } else if (state == 2) {
            	waterfull.stopLoadMore();
            }
            isOnclickSearch = false;
            if (errorMsg.equals("")) {
            	waterfull.setPullLoadEnable(true);
                if(videoPageInfo != null){
                    SearchVideo2Obj obj = videoPageInfo.getObj();
                    if(obj != null && obj.getList() != null && obj.getList().size() > 0){
                    	videolist = obj.getList();
                    }
                }else{
                    if (state == 2) {
                    	waterfull.setPullLoadEnable(false);
                    }else{
                    	waterfull.setPullRefreshEnable(false);
                    }
                    if (state == 1) {
                        waterfull.stopRefresh();

                    } else if (state == 2) {
                    	waterfull.stopLoadMore();
                    }
                    ToastAlone.showToast(OptionSearchActivity.this, "数据为空", 1);
                    return;
                }
                if (videolist != null && !videolist.isEmpty()) {

                    if (state == 1) {
                    	adapterVideo.LoadRefrush(videolist);
                    } else if (state == 2) {
                    	adapterVideo.LoadMore(videolist);
                    }
                    if(videolist.size() < pageSize){
                    	waterfull.setPullLoadEnable(false);
                    }
//                    adapterVideo.notifyDataSetChanged();

                } else {
                    if (state == 2) {
                    	waterfull.setPullLoadEnable(false);
                    }else{
                    	waterfull.setPullRefreshEnable(false);
                    }
                    ToastAlone.showToast(OptionSearchActivity.this, "数据为空", 1);
                }
                
            } else {
                ToastAlone.showToast(OptionSearchActivity.this, errorMsg, 1);
            }
        }
    }
    
    private class VideoAdapter extends BaseAdapter {
        private List<VideoDetailInfoNew> mInfos;
        private int mHeight;
        private int mWidth;
        private float margin;
        private float marginleft;
        private float marginbottom;
        public VideoAdapter(List<VideoDetailInfoNew> mInfos) {
            this.mInfos = mInfos;
            margin = OptionSearchActivity.this.getResources().getDimension(
    				R.dimen.list_item_margin);
            marginleft=OptionSearchActivity.this.getResources().getDimension(
					R.dimen.grid_item_second_titile_left_margin);
            marginbottom = OptionSearchActivity.this.getResources().getDimension(
    				R.dimen.grid_item_second_titile_bottom_margin);
            mHeight = Utils.computeImageHeight(OptionSearchActivity.this,(int)margin*3);
            mWidth = Utils.computeImageWidth(OptionSearchActivity.this, (int)margin*3, 2);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            ViewHolder holder;
            final VideoDetailInfoNew videoInfo = mInfos.get(position);

            if (convertView == null) {
                LayoutInflater layoutInflator = LayoutInflater.from(parent.getContext());
                convertView = layoutInflator.inflate(R.layout.grid_waterfall_item, null);
//                convertView = layoutInflator.inflate(R.layout.item_video_waterfull_list, null);
                holder = new ViewHolder();
                holder.ll_bg = (LinearLayout)convertView.findViewById(R.id.lay_item);
                holder.video_place = convertView.findViewById(R.id.video_place);
                holder.imageView2 = (ImageView) convertView.findViewById(R.id.iv_image);
                holder.desc = (TextView) convertView.findViewById(R.id.tv_title);
                holder.userName = (TextView) convertView.findViewById(R.id.tv_subtitle);
                convertView.setTag(holder);
            }

            holder = (ViewHolder) convertView.getTag();
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
    				mWidth, LayoutParams.MATCH_PARENT);
            LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
            		mWidth, LayoutParams.MATCH_PARENT);
    		if (position % 2 == 0) {
    			params.setMargins((int) margin, (int) margin, 0, 0);
    			param.setMargins((int) margin + (int) marginleft, (int) margin,
						(int) marginleft, (int)marginbottom);
    		} else {
    			params.setMargins((int) margin, (int) margin, (int) margin, 0);
    			param.setMargins((int) margin + (int) marginleft, (int) margin, (int) margin
						+ (int) marginleft, (int)marginbottom);
    		}
    		holder.video_place.setLayoutParams(params);
    		holder.userName.setLayoutParams(param);
    		holder.userName.setVisibility(View.GONE);
            if(videoInfo.getRecommendTitle() == null || videoInfo.getRecommendTitle().equals("") || videoInfo.getRecommendTitle().equals("null")){
            	holder.desc.setText(videoInfo.getTitle());
            }else{
            	holder.desc.setText(videoInfo.getRecommendTitle());
            }
            android.view.ViewGroup.LayoutParams Params = holder.imageView2.getLayoutParams();
    		Params.width =  mWidth; //设置图片的宽度
    		Params.height = mWidth*9/16;//设置图片的高度
    	    holder.imageView2.setLayoutParams(Params);
            if(videoInfo.getImgUrl() == null || videoInfo.getImgUrl().equals("")){
                holder.imageView2.setImageResource(R.drawable.video9_16_loading);
            }else {
            	ImageLoader.getInstance().displayImage(videoInfo.getImgUrl(), holder.imageView2,Constant.VIDEO_9_16_OPTION,null);                
            }
            holder.ll_bg.setOnClickListener(new OnClickListener() {
                
                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
//                ScenarioVideoInfo info = (ScenarioVideoInfo) parent.getItemAtPosition(position);
                    if(videoInfo.getStype().equals("1")){
                        ScenarioVideoInfo video = new ScenarioVideoInfo(videoInfo);
                        if(video != null){
                            OptionSearchActivity.this.startActivity(new Intent(OptionSearchActivity.this, PaikeVideoDetailActivity2.class).putExtra("videoInfo",video));
                        }
                    }
//                ScenarioVideoInfo info = new ScenarioVideoInfo(videoInfo);
//                if(info != null)
//                    startActivity(new Intent(OptionSearchNewActivity.this, PaikeVideoDetailActivity.class).putExtra("videoInfo",info ));
                }
            });
            if(videoInfo.getStype() != null && videoInfo.getStype().equals("0")){//0新闻1拍客
            	holder.userName.setText("第一视频");
            }else{
            	if(videoInfo.getRecommendDetail() == null || videoInfo.getRecommendDetail().equals("") || videoInfo.getRecommendDetail().equals("null")){
	                if(videoInfo.getUserInfo() != null){
	                	if(videoInfo.getUserInfo().getNickName() == null || videoInfo.getUserInfo().getNickName().equals("") 
	                			|| videoInfo.getUserInfo().getNickName().equals("null")){
	                		holder.userName.setText(videoInfo.getUserInfo().getUserName());
	                	}else{
	                		holder.userName.setText(videoInfo.getUserInfo().getNickName());
	                	}
	                }else{
	                	holder.userName.setText("让发现随时~");
	                }
            	}else{
            		holder.userName.setText(videoInfo.getRecommendDetail());
            	}
            }           
            return convertView;
        }
        private class ViewHolder {
            ImageView imageView2;
            TextView desc;
            TextView userName;
            LinearLayout ll_bg;
            View video_place;
        }

        @Override
        public int getCount() {
            return mInfos.size();
        }

        @Override
        public Object getItem(int arg0) {
            return mInfos.get(arg0);
        }

        @Override
        public long getItemId(int arg0) {
            return arg0;
        }

        public void LoadRefrush(List<VideoDetailInfoNew> datas) {
            mInfos.clear();
            mInfos.addAll(datas);            
            this.notifyDataSetChanged();
        }

        public void LoadMore(List<VideoDetailInfoNew> datas) {
            mInfos.addAll(datas);
            this.notifyDataSetChanged();
        }

        // public void addItemTop(List<ScenarioVideoInfo> datas) {
        // for (ScenarioVideoInfo info : datas) {
        // mInfos.a.addFirst(info);
        // }
        // }
    }

    //瀑布流的上拉加载，下拉刷新；
	@Override
	public void onRefresh() {
		// TODO Auto-generated method stub
		 currentPage = 1;
       AddItemToContainer(currentPage, TYPE_REFRUSH);
	}
	@Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("搜索页");
    }
    
    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("搜索页");
    }
	@Override
	public void onLoadMore() {
		// TODO Auto-generated method stub
		AddItemToContainer(++currentPage, TYPE_LOADMORE);
	}

	@Override
	public void onClick(View arg0) {
		switch(arg0.getId()){
		case R.id.item_search_player_right:
			Intent intent=new Intent(this,SearchMoreUserActivity.class);
			intent.putExtra("searchTxt", strKey);
			intent.putExtra("recordNum", 0);
			this.startActivity(intent);
			break;
		case R.id.item_search_special_right:
//			Intent intent3=new Intent(this,SearchMoreZhuanjiActivity.class);
//			intent3.putExtra("searchTxt", strKey);
//			intent3.putExtra("recordNum", 0);
//			this.startActivity(intent3);
			break;
		case R.id.item_search_theme_right:
			Intent intent4=new Intent(this,SearchMoreThemeActivity.class);
			intent4.putExtra("searchTxt", strKey);
			intent4.putExtra("recordNum", 0);
			this.startActivity(intent4);
			break;
		}
		
	}
	
	private TextWatcher watcher = new TextWatcher(){

        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub
            
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            // TODO Auto-generated method stub
            
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
            int strLength = editSearchCon.getText().toString().length();
            if(strLength <= 0){
            	btnClearText.setVisibility(View.GONE);
            }else{
            	btnClearText.setVisibility(View.VISIBLE);
            }
        }        
    };
}



